(ns demo.macrolearn)


;; ` 原原本本地直译过去， 不用`，let语句不被翻译
;; ~' 后面变量被直接翻译过去
;; '~ 变量名本身而非值
;; ~@ 表示多条语句
;; defmacro 定义macro ； macroexpand 展开宏


(defmacro debug [x] 
  `(println "----" '~x ":" ~x))

(defn make-connection [x] 
  (println "in make connection =" x) x)

(defn with-mongo [x] 
  (println "in with-mongo =" x))

(defmacro with-dict 
  "连接到meta库的 dict表操作"
  [& body]
  `(let [~'dbname "meta"
         ~'tbname "dict"
         ~'conn (make-connection ~'dbname)]
     (with-mongo ~'conn)
     (println "~'conn = " ~'conn )
     (println "~'tbname = " ~'tbname)
     (println "~@body = " ~@body)
     ~@body))
